package com.pug.user.rest;

import com.alibaba.fastjson.JSON;
import com.pug.user.dto.DeductionReqDTO;
import com.pug.user.dto.DeductionRespDTO;
import com.pug.user.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xq.pug.common.result.R;
import xq.pug.feign.dto.user.UserFeignReqDTO;
import xq.pug.feign.dto.user.UserFeignRespDTO;

/**
 * @program: xq_pug_alibabacloud_parent
 * @description:
 * @author: Mr.Ren
 * @create: 2023-04-16 16:08
 **/

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController  {

    @Autowired
    private IUserService userService;

    @GetMapping("/getUser")
    public R<String> getUser() {
        return R.ofSuccess("renGaoshuai");
    }


    @PostMapping("/queryUser")
    public R<UserFeignRespDTO> queryUser(@RequestBody UserFeignReqDTO dto){
        log.info("查询用户信息接口，请求参数【{}】", JSON.toJSONString(dto));
        UserFeignRespDTO userFeignRespDTO = userService.queryUser(dto);
        log.info("查询用户信息接口，请求参数【{}】", JSON.toJSONString(userFeignRespDTO));
        return R.ofSuccess(userFeignRespDTO);
    }


    /**
     * 用户扣款
     * @param dto
     * @return
     */
    @PostMapping("/deduction")
    public R<DeductionRespDTO> deduction(@RequestBody DeductionReqDTO dto){
        log.info("用户扣款接口，请求参数【{}】", JSON.toJSONString(dto));
        DeductionRespDTO resp = userService.deduction(dto);
        log.info("用户扣款接口，响应参数【{}】", JSON.toJSONString(resp));
        return R.ofSuccess(resp);
    }
}
